package com.handsome.迭代器模式;

import java.util.Iterator;
import java.util.List;

/**
 * @author niechun
 * @date 2023/3/19 13:54
 */
public class Output {
    //学院集合
    private List<College> list;

    public Output(List<College> list) {
        this.list = list;
    }

    //输出所有的学院
    public void printCollege(){
        Iterator<College> iterator = list.iterator();
        while (iterator.hasNext()) {
            College next = iterator.next();
            System.out.println(next.getName());
            printDepartment(next.getIterator());
        }

    }

    //输出所有的系
    public void printDepartment(Iterator iterator){
        while (iterator.hasNext()){
            Department next = (Department) iterator.next();
            System.out.println(next.getName());
        }

    }
}
